<template>
  <div class="home">
    <van-form @submit="onSubmit">
      <van-field
          size="large"
          v-model="code"
          name="代码"
          label="代码"
          placeholder="代码"
      />
      <van-field
          size="large"
          v-model="name"
          name="名称"
          label="名称"
          placeholder="名称"
      />
      <div style="margin: 16px;">
        <van-button size="large" round block type="info" native-type="submit" @click="getQueryData">查询</van-button>
      </div>
    </van-form>
    <van-list
        size="large"
        v-model="loading"
        :finished="finished"
        :immediate-check="false"
        finished-text="没有更多了"
        @load="getQueryData"
    >
      <van-cell size="large" v-for="(item, index) in list" :key="index" inset>
        <van-cell size="large" center title="编号" :value="index+1"/>
        <van-cell size="large" center title="编码" :value="item.code"/>
        <van-cell size="large" center title="名称" :value="item.name"/>
        <van-cell size="large" center title="主力" is-link :to="{name: 'fund', params: {stock: item.code, name: item.name}}"/>
      </van-cell>
    </van-list>
  </div>
</template>

<script>

import axios from "axios";

export default {
  name: "Home",
  data() {
    return {
      code: '',
      name: '泸州',
      list: [],
      loading: false,
      finished: false,
      stock: '000568',
      market: 'sz'
    }
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values);
    },
    getQueryData() {
      axios.get('http://alfred168.cn:1067/akshare/getStockInfoPartCodeName', {
        params: {
          name: this.name,
          code: this.code
        }
      }).then(res => {
        this.list = res.data
        this.finished = true
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  position: relative;
  height: 100%;
}
</style>
